#include "PopLayer.h"
USING_NS_CC;

CCScene* PopLayer::scene()
{
	// 'scene' is an autorelease object
	CCScene *scene = CCScene::create();

	// 'layer' is an autorelease object
	PopLayer *layer = PopLayer::create();

	// add layer as a child to scene
	scene->addChild(layer);

	// return the scene
	return scene;
}

bool PopLayer::init()
{
	if ( !CCLayer::init() )
	{
		return false;
	}

	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

	CCTextFieldTTF * textfield  = CCTextFieldTTF::textFieldWithPlaceHolder(content, "Thonburi",20);
	textfield->setPosition(ccp(origin.x + visibleSize.width * 0.5, origin.y + visibleSize.height * 0.5));
	addChild(textfield);

	CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
		"CloseNormal.png",
		"CloseSelected.png",
		this,
		menu_selector(PopLayer::close));
	pCloseItem->setTag(1);

	pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
		origin.y + pCloseItem->getContentSize().height/2));

	// create menu, it's an autorelease object
	CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
	pMenu->setPosition(CCPointZero);
	this->addChild(pMenu, 1);
	return true;
}

void PopLayer::close( CCObject* pSender )
{
	CCDirector::sharedDirector()->popScene();
}